<?php

namespace Hdphim\Modules\User\Models;
use Hdphim\Modules\Api\Models\Users\Users as ApiUserModel;
use Hdphim\Modules\Api\Models\Users\UserEmailConfirmations as ApiUserEmailConfirmations;

class Users extends ApiUserModel
{
      /*
     * Send a confirmation e-mail to the  user if the account is not active
     */
    public function afterSave()
    {
        if ($this->active == 'N') 
        {
            $emailConfirmation = new ApiUserEmailConfirmations();

            $emailConfirmation->setUserId($this->id);

            if ($emailConfirmation->save()) {
                $this->getDI()
                    ->getFlash()
                    ->notice('A confirmation mail has been sent to ' . $this->email);
            }
        }
    }
}